
//绘制直线
var draw_line = function (ctx, x1, y1, x2, y2, width, color) {
    ctx.beginPath();
    // 设置线条的颜色
    ctx.strokeStyle = color;
    // 设置线条的宽度
    ctx.lineWidth = width;
    ctx.moveTo(x1, y1);
    ctx.lineTo(x2, y2);
    ctx.closePath();
}
//绘制圆形
var draw_circle = function (ctx, x, y, r, start, end, color, type) {
    var unit = Math.PI / 180;
    ctx.beginPath();
    ctx.arc(x, y, r, start * unit, end * unit);
    if (type == "fill")
        ctx.fillStyle = color;
    else
        ctx.strokeStyle = color;
    ctx.closePath();
    type == "fill" ? ctx.fill() : ctx.stroke();
}
//绘制三角形
// x1(2、3),y1(2、3)-三角形的三个点的坐标；color-绘制颜色；type-绘制类型（'fill'和'stroke'）
var draw_triangle = function (ctx, x1, y1, x2, y2, x3, y3, color, type) {
    ctx.beginPath();
    ctx.moveTo(x1, y1);
    ctx.lineTo(x2, y2);
    ctx.lineTo(x3, y3);
    if (type == "fill")
        ctx.fillStyle = color;
    else
        ctx.strokeStyle = color;
    ctx.closePath();
    type == "fill" ? ctx.fill() : ctx.stroke();
}
//绘制矩形
var draw_rectangle = function (ctx, x, y, width, height, radius, color, type) {
    ctx.beginPath();
    ctx.moveTo(x, y + radius);
    ctx.lineTo(x, y + height - radius);
    ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
    ctx.lineTo(x + width - radius, y + height);
    ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
    ctx.lineTo(x + width, y + radius);
    ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
    ctx.lineTo(x + radius, y);
    ctx.quadraticCurveTo(x, y, x, y + radius);
    if (type == "fill")
        ctx.fillStyle = color;
    else
        ctx.strokeStyle = color;
    ctx.closePath();
    type == "fill" ? ctx.fill() : ctx.stroke();
}
//绘制多边形
var draw_polygon = function (ctx, conf) {
    var x = conf && conf.x || 0;  //中心点x坐标
    var y = conf && conf.y || 0;  //中心点y坐标
    var num = conf && conf.num || 3;   //图形边的个数
    var r = conf && conf.r || 100;   //图形的半径
    var width = conf && conf.width || 5;
    var strokeStyle = conf && conf.strokeStyle;
    var fillStyle = conf && conf.fillStyle;
    //开始路径
    ctx.beginPath();
    var startX = x + r * Math.cos(2 * Math.PI * 0 / num);
    var startY = y + r * Math.sin(2 * Math.PI * 0 / num);
    ctx.moveTo(startX, startY);
    for (var i = 1; i <= num; i++) {
        var newX = x + r * Math.cos(2 * Math.PI * i / num);
        var newY = y + r * Math.sin(2 * Math.PI * i / num);
        ctx.lineTo(newX, newY);
    }
    ctx.closePath();
    //路径闭合
    if (strokeStyle) {
        ctx.strokeStyle = strokeStyle;
        ctx.lineWidth = width;
        ctx.lineJoin = 'round';
        ctx.stroke();
    }
    if (fillStyle) {
        ctx.fillStyle = fillStyle;
        ctx.fill();
    }
}
//绘制虚线
var draw_Dashed = function (ctx, moveto, lineto, color, lineWidth) {
    ctx.lineWidth = lineWidth;
    ctx.strokeStyle = color;
    ctx.beginPath();
    ctx.setLineDash([5, 7]);
    ctx.moveTo(moveto[0], moveto[1]);
    ctx.lineTo(lineto[0], lineto[1]);
    ctx.stroke();
}
function drawDashed() {
    cxt.lineWidth = lineWidth;
    cxt.strokeStyle = color;
    cxt.beginPath();
    cxt.setLineDash([5, 15]);
    cxt.moveTo(20, 20);
    cxt.lineTo(400, 20);
    cxt.stroke();
}
//画虚线的圆
const drawDashRound = (ctx, x, y, radius, color, type, width, step = 5) => {
    const count = Math.floor(360 / step);
    step = 5 / 180 * Math.PI * 1;
    for (let b = 0, e = step / 2; e <= 360; b += step, e += step) {
        ctx.beginPath()
        if (type == "fill")
            ctx.fillStyle = color;
        else
            ctx.strokeStyle = color;
        ctx.width = width;
        ctx.arc(x, y, radius, b, e);
        ctx.stroke();
    }
}